package cn.net.shuxing.yifu.common.util;

import tk.mybatis.mapper.entity.Example;

public class CommonExample extends Example {

    protected Criteria criteria = this.createCriteria(this.getEntityClass());

    protected Criteria createCriteria(Class<?> entityClass)
    {
        return super.createCriteria();
    }

    public CommonExample(Class<?> entityClass) {
        super(entityClass);
        init();
        this.and(criteria);
    }

    private void init()
    {
        equals("deleted",0);
    }

    public CommonExample(Class<?> entityClass, boolean exists) {
        super(entityClass, exists);
        init();
    }

    public CommonExample(Class<?> entityClass, boolean exists, boolean notNull) {
        super(entityClass, exists, notNull);
        init();
    }

    public CommonExample between(String property, Object low, Object high)
    {
        criteria.andGreaterThanOrEqualTo(property,low)
                .andLessThanOrEqualTo(property,high);
        return this;
    }

    public CommonExample equals(String property, Object value)
    {
        criteria.andEqualTo(property,value);
        return this;
    }

    public Criteria getCriteria() {
        return criteria;
    }
}
